//实现hero动画

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HeroAnimationRouteA extends StatelessWidget{

  const HeroAnimationRouteA({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
         title: "hero动画",
         home: Scaffold(
           appBar: AppBar(title: Text("hero动画测试"),),
             body:  Container(
               alignment: Alignment.topCenter,
               child: Child(),
             ),
         ),
    );
  }
}

class Child extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return  Column(
      children: [
        InkWell(
          child: Hero(
            tag: "avatar", //唯一标记，前后两个路由页Hero的tag必须相同
            child: ClipOval(
              child: Image.network("https://img0.baidu.com/it/u=3365573645,2073973856&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500"
                ,width: 50.0,),
            ),
          ),
          onTap: (){
            // 路由跳转
            Navigator.push(context,PageRouteBuilder(pageBuilder:(context,
                animation,
                secondaryAnimation,){

              return FadeTransition(
                opacity: animation,
                child: Scaffold(
                  appBar: AppBar(
                    title: const Text("原图"),
                  ),
                  body: HeroAnimationRouteB(),
                ),
              );
            }));

          },
        ),
        const Padding(
          padding: EdgeInsets.only(top: 8.0),
          child: Text("点击头像"),
        )
      ],);
  }
}

class HeroAnimationRouteB  extends StatelessWidget{

      @override
      Widget build(BuildContext context) {

       return Center(
         child: Hero(
           tag: "avatar",
           child: Image.network("https://img0.baidu.com/it/u=3365573645,2073973856&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
           ),
         ),
       );
  }
}

